<template>
  <div>
    <div class="form">
      <div class="search">
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="medium"
          :inline="true"
        >
          <el-form-item label="设备选择" prop="device">
            <el-select
              v-model="queryParams.device"
              placeholder="请选择"
              style="width: 100%"
            >
              <el-option
                v-for="item in deviceList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="能耗" prop="energy">
            <el-select
              v-model="queryParams.energy"
              placeholder="请选择"
              style="width: 100%"
            >
              <el-option
                v-for="item in energyList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="统计方式" prop="way">
            <el-select
              v-model="queryParams.way"
              placeholder="请选择"
              style="width: 100%"
            >
              <el-option
                v-for="item in wayList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="选择时间" prop="time">
            <el-date-picker
              v-model="queryParams.time"
              v-if="queryParams.way === '1'"
              type="date"
              placeholder="请选择"
              value-format="yyyy-MM-dd"
            >
            </el-date-picker>
            <el-date-picker
              v-model="queryParams.time"
              v-if="queryParams.way === '2'"
              type="month"
              placeholder="请选择"
              value-format="yyyy-MM"
            >
            </el-date-picker>
            <el-date-picker
              v-model="queryParams.time"
              v-if="queryParams.way === '3'"
              type="year"
              placeholder="请选择"
              value-format="yyyy"
            >
            </el-date-picker>
          </el-form-item>
        </el-form>
        <div>
          <el-button type="primary" @click="drawLine()" class="searchBtn"
            >搜索</el-button
          >
          <el-button @click="reset()" class="searchBtn">重置</el-button>
        </div>
      </div>
      <div id="chart" style="width: 100%; height: 700px"></div>
    </div>
  </div>
</template>

<script>
import {
  ledgerList,
  ledgerAdd,
  ledgerUpdate,
  ledgerDel,
  ledgerDetail,
  standardList,
  standardAdd,
  standardUpdate,
  standardDel,
  standardDetail,
} from "@/api/system/device";
import {} from "@/api/article";
import echarts from "echarts";
import moment from "moment";
import { getToken } from "@/utils/auth";
export default {
  components: {},
  filters: {
    statusList: function (value) {
      switch (value) {
        case "1":
          return "已提交";
        case "2":
          return "已分派";
        case "3":
          return "已解决";
      }
    },
  },
  data() {
    return {
      form: {},
      queryParams: {
        way: "1",
        energy: "1",
      },
      color: ["#4f8ae3", "#16bf16", "#ff8f2c", "#cf1a1a"],
      rules: {
        deviceName: [{ required: true, message: "请输入", trigger: "blur" }],
        deviceId: [{ required: true, message: "请输入", trigger: "blur" }],
        deviceModule: [
          { required: true, message: "请输入", trigger: "change" },
        ],
      },
      wayList: [
        { value: "1", label: "日度" },
        { value: "2", label: "月度" },
        { value: "3", label: "年度" },
      ],
      energyList: [
        { value: "1", label: "总量" },
        { value: "2", label: "峰谷平" },
      ],
      deviceList: [
        { value: "1", label: "总量" },
        { value: "2", label: "电表1" },
        { value: "3", label: "电表2" },
        { value: "4", label: "电表3" },
        { value: "5", label: "电表4" },
        { value: "6", label: "电表5" },
      ],
      totalData: [
        { name: "总用电能耗", number: "1000" },
        { name: "峰值总能耗", number: "1000" },
        { name: "平值总能耗", number: "1000" },
        { name: "谷值总能耗", number: "1000" },
      ],
      type: "",
      uploadUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址
      token: {
        Authorization: getToken(),
      },
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      modelClass: null,
      visible: false,
      list: [],
      listLoading: false,
      total: 0,
      limit: 10,
      curPage: 1,
      listData: [],
      studentName: "",
      // studentClass: '',
      phonenumber: "",
      work: "",
      page: this.$route.query.page,
      personClass: "",
      classList: [],
      userId: null,
      imageUrl: "",

      imageName: null,
      title: "",
    };
  },
  created() {},
  mounted() {
    this.drawLine();
  },
  methods: {
    drawLine() {
      let series = [];
      let unit = "";
      if (this.queryParams.energy == 1) {
        unit = "总量";
        series = [
          {
            name: "总量",
            type: "bar",
            barWidth: "30px",
            data: [10, 52, 200, 334, 390, 330, 220],
          },
        ];
      } else {
        unit = "峰谷平";
        series = [
          {
            name: "峰",
            type: "bar",
            barWidth: "30px",
            data: [30, 102, 300, 434, 590, 630, 320],
          },
          {
            name: "谷",
            type: "bar",
            barWidth: "30px",
            data: [10, 32, 100, 234, 290, 230, 120],
          },
          {
            name: "平",
            type: "bar",
            barWidth: "30px",
            data: [20, 52, 200, 334, 390, 330, 220],
          },
        ];
      }
      this.chartLine = echarts.init(document.getElementById("chart"));
      // 指定图表的配置项和数据
      var option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            data: [
              "2025-02-01",
              "2025-02-02",
              "2025-02-03",
              "2025-02-04",
              "2025-02-05",
              "2025-02-06",
              "2025-02-07",
            ],
            axisTick: {
              alignWithLabel: true,
            },
          },
        ],
        yAxis: [
          {
            name: unit,
            type: "value",
          },
        ],
        series: series,
      };

      // 使用刚指定的配置项和数据显示图表。
      this.chartLine.setOption(option, true);
    },
  },
};
</script>
<style scoped>
.form {
  padding-left: 26px;
  padding-right: 24px;
  padding-top: 24px;
  background: #fff;
}
.search {
  display: flex;
  position: relative;
}
.search_info {
  width: 192px;
  height: 40px;
  margin-right: 16px;
}
.searchBtn {
  margin-left: 16px;
  height: 36px;
}
.sortStyle {
  height: 19px;
  float: right;
  /* right: 24px; */
  margin-top: 20px;
  margin-bottom: 30px;
}
.pos_right_btn {
  position: absolute;
  right: 0;
}
.opt_font {
  cursor: pointer;
  color: #2e82ff;
}
.detail_title {
  font-size: 16px;
  font-weight: 400;
  color: #212121;
  line-height: 22px;
}
.detail_title span {
  padding-left: 4px;
  background: #1e88e5;
  margin-right: 12px;
}
.row {
  display: flex;
  padding-bottom: 12px;
}
.detail_info {
  padding-top: 16px;
}
.info_left {
  display: flex;
}
.info_right {
  display: flex;
  padding-left: 202px;
}
.info_left_title {
  font-size: 14px;
  font-weight: 400;
  color: #616161;
  line-height: 20px;
  width: 112px;
  margin-right: 16px;
}
.info_left_content {
  font-size: 14px;
  font-weight: 400;
  color: #212121;
  line-height: 20px;
  width: 150px;
}
.pos_top {
  padding-top: 12px;
}
.detailTable {
  margin-top: 16px;
}
.opt_font {
  color: #1e88e5;
  cursor: pointer;
}
.page_pos {
  text-align: right;
  padding-top: 10px;
}
.backBtn {
  text-align: center;
  margin-top: 10px;
}
/deep/ .el-dialog {
  display: flex;
  flex-direction: column;
  margin: 0 !important;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  /* max-height: calc(100% -30px); */
  /* max-width: ; */
}
/deep/ .el-dialog .el-dialog__body {
  flex: 1;
  height: 700px;
  overflow-y: auto;
  padding-top: 0;
}
.tab {
  display: flex;
  position: absolute;
  right: 32px;
  top: 14px;
}
.tab_border {
  border: 1px solid #409eff;
  color: #409eff;
  padding: 10px 12px;
  font-size: 14px;
  margin-right: 16px;
}
.change {
  border: 1px solid #f56c6c;
  color: #f56c6c;
}
.listTable {
  margin-top: 17px;
}
.out {
  position: absolute;
  right: 0;
}
.footer {
  text-align: center;
}
.point {
  cursor: pointer;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
  border: 1px dashed #000;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
/* 自定义文本按钮的样式 */
.red-text-button {
  color: red; /* 设置文本颜色为红色 */
}
.pannel {
  width: 100%;
  color: #fff;
  border-radius: 4px;
  line-height: 32px;
}
.flex-between {
  justify-content: space-between;
}
.box {
  padding: 6px 16px;
}
.pannel-name {
  font-size: 20px;
}
.pannel-number {
  font-size: 24px;
  /* font-weight: bold; */
}
</style>
